Skip to content

Conversation

@Avid29
Copy link
Contributor

@Avid29 Avid29 commented Oct 7, 2025

This PR builds on #734 by removing the explicit 5 accent color properties on the AccentAnalyzer and replaces it with an IList<ColorPaletteSelector> property.

New XAML usage example:

<*.Resources>
    <helpers:ColorPaletteSampler x:Name="ColorPaletteSampler"
                                 Source="{x:Bind SampledImage}">
        <helpers:AccentColorPaletteSelector x:Name="AccentPalette"
                                            MinColorCount="3" />
        <helpers:ColorWeightPaletteSelector x:Name="WeightedColorPalette"
                                            MinColorCount="1" />
        <helpers:BaseColorPaletteSelector x:Name="BasePalette"
                                          MinColorCount="1" />
    </helpers:ColorPaletteSampler>
</*.Resources>
...

<!--  Any number of bindings you'd like with indexed SelectedColors!  -->
<SolidColorBrush Color="{x:Bind WeightedColorPalette.SelectedColors[0], FallbackValue=Transparent, Mode=OneWay}" />
<SolidColorBrush Color="{x:Bind AccentPalette.SelectedColors[1], FallbackValue=Transparent, Mode=OneWay}" />

This allows a dynamic number of extracted color properties through combinations of color palette selectors, and even more by implementing your own custom ColorPaletteSelector!

Similar behavior was previously possible by making a derived class from the AccentAnalyzer and overriding the SelectAccentColors method. I believe this is a cleaner solution though, moving even dynamic numbers of extracted colors into pure XAML.

Example in use:
image

@Avid29 Avid29 force-pushed the ColorAnalyzer/Palettes branch from ea97b51 to 4e2e14b Compare October 7, 2025 01:53
- Trimmed colorfulness info from AccentColorInfo
- Renamed AccentColorInfo to PaletteColor
- Removed colorfulness calculations for AccentAnalyzer
- Renamed AccentAnalyzer to ColorPaletteSampler
- Replaced statically enumerated PaletteSelector properties with index bindable SelectedColors with dynamic min count
- Replaced phrase 'prominence' with 'weight' and 'fraction'
@Avid29 Avid29 changed the title Moved AccentAnalyzer color properties into ColorPalette children Refactor AccentAnalyzer into ColorPaletteSampler Oct 10, 2025
@Arlodotexe Arlodotexe enabled auto-merge October 10, 2025 04:15
@Arlodotexe Arlodotexe merged commit acda1c3 into CommunityToolkit:main Oct 10, 2025
23 of 24 checks passed
@Avid29 Avid29 deleted the ColorAnalyzer/Palettes branch October 10, 2025 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants